package com.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.struts2.ServletActionContext;

import com.vo.StoreForm;

public class FileUtil {
	public static String fileUp(StoreForm store) throws IOException{
	System.out.println(store.getPhotoFileName()+"..............fileUtil");
		String path=ServletActionContext.getServletContext().getRealPath("/StoreImages");
//		System.out.println(path+"........fileroot");
		String fileroot=path+"\\"+store.getName()+store.getPhotoFileName();
		OutputStream os = new FileOutputStream(fileroot);
	    InputStream is=new FileInputStream(store.getPhoto());
	    byte[] buf=new byte[1024];
	    int length=0;
	    while((length=is.read(buf))!=-1){
	    	os.write(buf, 0, length);
	    }
	    is.close();
	    os.close();
		
		return store.getName()+store.getPhotoFileName();
		
	}
}
